<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>支付商品设置</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="common.jsp"%>
</head>
<body style="margin-top:-10px;">
	<div style="margin-top:20px;">
		<button id="productBox" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#productBoxDiv">打开修改窗口</button>
	</div>
	<div>
		<table id="productTable" class="text-nowrap"></table>
	</div>
	<!-- 修改支付产品窗口 -->
	<div class="modal fade" id="productBoxDiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改产品信息</h4>
            </div>
            <div class="modal-body">
           		 <form id="productForm" method='post' class="form-inline" enctype="multipart/form-data">
				 	<div class="form-group">
				    	<label for="exampleInputName2">产品名称：</label>
				    	<input id="productName" name="productName" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-left:20px;">
				    	<label for="exampleInputEmail2">产品金额：</label>
				    	<input id="productMoney" name="productMoney" type="number" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-top:20px;">
				  		<label for="exampleInputEmail2">一级返利：</label>
				  		<input id="rebateOne" name="rebateOne" type="number" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-left:20px;">
				  		<label for="exampleInputEmail2">二级返利：</label>
				  		<input id="rebateTwo" name="rebateTwo" type="number" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-top:20px;">
				  		<label for="exampleInputEmail2">三级返利：</label>
				  		<input id="rebateThree" name="rebateThree" type="number" class="form-control"/>
				  	</div>
				  	<div class="form-group" style="margin-top:20px;">
				  		<label for="exampleInputEmail2">按钮文字：</label>
				  		<textarea id="productTxt" name="productTxt" class="form-control" rows="3" style="width:475px;"></textarea>
				  	</div>
				  	<input id="productId" name="id" hidden="ture"/>
				</form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="submitProduct()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
	</div>
</body>
<script type="text/javascript">
//重载表格
$(function(){
	//隐藏打开图片窗口按钮
	$('#productBox').hide();
	//加载表格
	$("#productTable").bootstrapTable({
		url: "${pageContext.request.contextPath}/product/findProduct.do",
		method: "post",
		cache: false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		toolbar: "#toolbar",
		classes: "table table-hover table-striped",
		height:520,
		pagination: true,
		sidePagination: 'server',
		search: false,
		smartDisplay:false,
		sortOrder: "desc",
		searchText: "",
		showRefresh: false,
		showToggle: false,
		singleSelect: true,
		showPaginationSwitch: false,
		pageNumber: 1,
		pageSize: 5,
		pageList: [5, 10, 20, 40],
		clickToSelect: true,
		onCheck: function (row) {
		},
		queryParamsType: "undefined",
		queryParams: function (params) {
			var params = {
				pageNum: params.pageNumber,
				pageSize: params.pageSize,
				sortBy: params.sortOrder,
			}
			return params;
		},
		columns: [
			{
				field: "productName",
				title: "产品名称"
			}, {
				field: "productMoney",
				title: "产品金额"
			}, {
				field: "rebateOne",
				title: "一级返利金额"
			}, {
				field: "rebateTwo",
				title: "二级返利金额"
			}, {
				field: "rebateThree",
				title: "三级返利金额"
			}, {
				field: "productTxt",
				title: "按钮文字"
			}
			
		],
		responseHandler: function (data) {//onLoad前处理数据源
			return data;
		},
		onLoadSuccess: function (data) {	//成功时执行
		},
		onLoadError: function (data) {	//失败时执行
			return;
		},
		//双击行打开修改界面
		onDblClickRow:function(row){
			//打开修改窗口
			$('#productBox').click();
			
			//控件赋值
			//产品名称
			$('#productName').val(row.productName);
			//产品金额
			$('#productMoney').val(row.productMoney);
			//上级返利金额
			$('#rebateOne').val(row.rebateOne);
			$('#rebateTwo').val(row.rebateTwo);
			$('#rebateThree').val(row.rebateThree);
			//按钮文本			
			$('#productTxt').val(row.productTxt);
			$('#productId').val(row.id);
		}
	});
})
//新增银行产品信息
function submitProduct(){
	if($('#productName').val() == ''){
		return alert("请输入产品名称！");
	}
	if($('#productMoney').val() == ''){
		return alert("请输入产品金额！");
	}
	if($('#rebateOne').val() == ''){
		return alert("请输入一级返利金额！");
	}
	if($('#rebateTwo').val() == ''){
		return alert("请输入二级返利金额！");
	}
	if($('#rebateThree').val() == ''){
		return alert("请输入三级返利金额！");
	}
	if(confirm("确定修改?")){
		//提交表单，修改产品信息
		$('#productForm').attr("action","${pageContext.request.contextPath}/product/updateProduct.do");
		$('#productForm').submit();
		alert('修改成功！');
	}
}
</script>
</html>




